package com.iefgames.cs.pople;

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mortbay.util.ajax.Continuation;
import org.mortbay.util.ajax.ContinuationSupport;

import com.iefgames.cs.manager.PopleManager;
import com.iefgames.cs.shout.AbstractShout;
import com.iefgames.cs.shout.CometShout;

public class Us extends Pople {

	@Override
	public boolean isCs() {
		return false;
	}

	@Override
	public void newcomet(HttpServletRequest request, HttpServletResponse response) {
		//检查是否含有csUuid，如果没有csUuid或者此csUuid不在线那么重新生成一个供us作用
		String csUuid = request.getParameter("csUuid");
		if (csUuid == null
				|| csUuid.length() != 32
				|| !PopleManager.isOnline(csUuid)) {
			//通知us有新的csUuid，以后以此uuid通信
			CometShout shout = new CometShout();
			shout.setCsUuid(PopleManager.getRandomOnlineCsUuid());

			addMsg(shout);
		}
		
		//初始化continuation
		Continuation continuation = ContinuationSupport.getContinuation(request, null);
		setContinuation(continuation);
		
		setState(State.Online);
		setNoCacheHeader(response);
		
		PopleManager.set(this);
	}
	
	public Us(String uuid) {
		setUuid(uuid);
	}
}
